/******************************************************************
 * Title: unscrun.sc
 * Author:  Brian Peck
 * Date: Spring 2011
 * Description: Specification model for unscrun (in DES)
 *****************************************************************/
#include <stdio.h>
import "i_receiver";
import "i_sender";

behavior desUnscrun(i_receiver ir, i_sender is)
{
  const char* bName = "desUnscrun";
  void main(void) {
    unsigned long outofData[2];
    unsigned long intoData[2];
    unsigned long * outof;
    unsigned char * into;


    while (1) {
      into = (unsigned char*)intoData;
      outof = outofData;

      ir.receive(&outofData[0], sizeof(unsigned long));
      ir.receive(&outofData[1], sizeof(unsigned long));

      printf("%s: Received block[0]: 0x%lx, block[2]: 0x%lx\n", bName, outofData[0], outofData[1]);

      *into++ = (*outof >> 24) & 0xffL;
      *into++ = (*outof >> 16) & 0xffL;
      *into++ = (*outof >>  8) & 0xffL;
      *into++ =  *outof++      & 0xffL;
      *into++ = (*outof >> 24) & 0xffL;
      *into++ = (*outof >> 16) & 0xffL;
      *into++ = (*outof >>  8) & 0xffL;
      *into   =  *outof	       & 0xffL;

      printf("%s: Sending block[0]: 0x%lx, block[2]: 0x%lx\n", bName, intoData[0], intoData[1]);

      //notify(start);

      //input1 = intoData[0];
      is.send(&intoData[0], sizeof(unsigned long));

      //input2 = intoData[1];
      is.send(&intoData[1], sizeof(unsigned long));

      //wait(done);
    }
  } // end main
}; // end behavior unscrun
